#! /bin/bash

## Author: huanlf AT gmail.com li-jiahuan
## 清理ubuntu的多余帮助文件、多国语言支持, 和其它不常用的包
## 在kubuntu 9.04上通过测试

echo "删除 OOO的帮助文档, 1.4G ..."
dpkg -l | grep openoffice.org-help |
 awk '!/openoffice.org-help-zh/ { print $2 }' |
 xargs  | sudo xargs apt-get  purge -y

dpkg -l | grep openoffice.org-l11  |
 grep -v openoffice.org-l10n-common |
 awk '! /zh-(cn|tw)/ { print $2 }' | 
 xargs | sudo xargs  apt-get purge -y

dpkg -l | awk '/openoffice.org-thesaurus-/ { print $2 }' | 
 xargs |  sudo xargs  apt-get purge -y
 
echo "------------------------------------------------"

echo "删除 GIMP的帮助文档, 100M ..."
dpkg -l | grep gimp-help |
 awk '! /common|zh-(cn|tw)/ { print $2 }' |
 xargs | sudo xargs apt-get purge -y
echo "------------------------------------------------"

echo "删除 KDE 多国语言 900M ..."
dpkg -l | grep language-pack-kde- |
 awk '!/(zh|en)(-base)?/ { print $2 }' |
 xargs | sudo xargs apt-get purge -y

dpkg -l | grep -v language-pack-kde |
 grep language-pack |
 awk '! /language-pack-(zh|en)(-base)?/ { print $2 }' |
 sudo xargs apt-get purge -y

dpkg -l | awk '/language-support-writing-/ { print $2 }' |
 sudo xargs apt-get purge -y

echo "------------------------------------------------"

echo "删除打印(CUPS)相关的文件 ..."
sudo apt-get purge -y cups cups-common cups-bsd \
 cups-client foomatic-db-gutenprint foomatic-db \
 foomatic-db-engine

echo "------------------------------------------------"

echo "删除拼写检查相关的文件"
dpkg -l | awk '/myspell/ { print $2 }'  | xargs | 
  sudo xargs apt-get purge -y

echo "------------------------------------------------"

echo "安装 deborphan 用以清理多余的库文件 ..."
if ! dpkg -l deborphan &> /dev/null; then
    sudo apt-get install deborphan
fi

echo "------------------------------------------------"

echo "删除无用的库文件 ..."
deborphan | sudo xargs apt-get purge -y

echo "------------------------------------------------"

echo "删除缓存的deb文件 ..."
sudo apt-get clean

echo "------------------------------------------------"

echo "删除因依赖而安装、但已经不再被使用的deb文件 ..."
sudo apt-get autoremove -y

echo "ALL DONE"
